package com.zzb.framework.event.service;

import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zzb.framework.common.BaseService;
import com.zzb.framework.event.dao.SysEventNotifyDAO;
import com.zzb.framework.event.entity.SysEventNotify;

import com.zzb.framework.common.BaseResponse;
import com.zzb.framework.common.ServiceException;
import com.zzb.framework.role.entity.IUser;
import com.zzb.framework.validator.annotation.ValidatorEnabled;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 事件通知方法 service类
 */
@Service("sysEventNotifyService")
public class SysEventNotifyService extends BaseService<SysEventNotifyDAO, SysEventNotify> {
    private static final Logger logger = LoggerFactory.getLogger(SysEventNotifyService.class);
    @Autowired
    private SysEventNotifyDAO sysEventNotifyDAO;

    @Override
    public SysEventNotifyDAO getDAO() {
        return sysEventNotifyDAO;
    }

    /**
     * 删除事件通知方法
     */
    public BaseResponse deleteSysEventNotify(String id, IUser operator) throws ServiceException {
        //TODO  ZZB 20170222
        return deleteById(id);
    }

    /**
     * 保存事件通知方法
     */
    @ValidatorEnabled
    public BaseResponse<SysEventNotify> saveSysEventNotify(SysEventNotify sysEventNotify, IUser operator) throws ServiceException {
        logger.info("正在保存事件通知方法[" + JSON.toJSONString(sysEventNotify) + "][" + JSON.toJSONString(operator) + "]");
        //TODO  ZZB 20170222
        return insertOrUpdate(sysEventNotify, operator);
    }

    /**
     * 通过eventId获取事件通知列表
     */
    public List<SysEventNotify> findByEventIdOrderByExecuteOrderAsc(String eventId) {
        return getDAO().getMapper().selectList(new EntityWrapper<SysEventNotify>()
                .eq("event_id", eventId)
                .eq("activate", 1).orderBy("execute_order", true));
    }
}
